package root.sport_manager.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import root.sport_manager.entity.po.SystemMenu;
import root.sport_manager.entity.vo.MenuVo;
import root.sport_manager.mapper.SystemMenuMapper;
import root.sport_manager.service.SystemMenuService;
import root.sport_manager.tools.util.TreeUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SystemMenuServiceImpl implements SystemMenuService {
    @Autowired
    private SystemMenuMapper systemMenuMapper;
    @Override
    public Map<String,Object> menu() {
        Map<String,Object> map = new HashMap<>(16);
        Map<String,Object> home = new HashMap<>(16);
        Map<String,Object> logo = new HashMap<>(16);
        List<SystemMenu> menuList = systemMenuMapper.getSystemMenuByStatusAndSort();
        //System.out.println(menuList);
        List<MenuVo> menuInfo = new ArrayList<>();
        for(SystemMenu e : menuList){
            MenuVo menuVO = new MenuVo();
            menuVO.setId(e.getKey().getId());
            menuVO.setPid(e.getPid());
            menuVO.setHref(e.getKey().getHref());
            menuVO.setTitle(e.getKey().getTitle());
            menuVO.setIcon(e.getIcon());
            menuVO.setTarget(e.getTarget());
            menuInfo.add(menuVO);
        }
        //map.put("homeInfo", "{title: '首页',href: '/page/welcome-1.html?t=1'}}");
        map.put("menuInfo", TreeUtil.toTree(menuInfo, 0L));
        home.put("title","首页");
        home.put("href","page/welcome-1.html?t=1");//控制器路由,自行定义
        logo.put("title","后台管理系统");
        logo.put("image","images/logo.png");//静态资源文件路径,可使用默认的logo.png
        map.put("homeInfo",home);
        map.put("logoInfo",logo);
        return map;
    }
}
